<template>
  <div class="chat">
    <template v-for="(item, index) in messagedata" :key="item + index">
      <div :class="item.type == 1 ? 'message1' : 'message2 '">
        <span>
          {{ item.message }}
        </span>
      </div>
    </template>
    <div class="zinput">
      <el-input
        size="large "
        placeholder="评论千万条，安全第一条"
        v-model="sendmessage"
      >
      </el-input>
      <el-button @click="sendclick">发送{{ userid }}</el-button>
    </div>
  </div>
</template>

<script >
import { defineComponent } from "vue";
import { useStore } from "vuex";

import { onsocket } from "@/utils/usesocket";

export default defineComponent({
  components: {},
  props: {
    userid: {
      type: Number,
      default: 0,
    },
  },
  setup(props) {
    const store = useStore();

    //输入框数据
    const messagedata = store.getters["ws/getmessagedata"];
    const { sendclick, sendmessage } = onsocket(store, props.id);

    return { sendclick, sendmessage, messagedata };
  },
});
</script>

<style scoped lang="less">
.chat {
}
</style>
